﻿using RpcClient.Interface;
using RpcHelper.Error;
using RpcModel;
using RpcModel.ErrorManage;

namespace RpcClient.Error
{
    internal class ErrorExtendService : IExtendService
    {
        private IErrorService _Service;
        private ITcpRouteCollect _RouteService;
        public ErrorExtendService(IErrorService service, ITcpRouteCollect routeService)
        {
            this._Service = service;
            this._RouteService = routeService;
        }

        public string Name => "ErrorService";

        public void Load(IRpcService service)
        {
            service.InitComplating += this.Service_InitComplating;
        }
        private void Service_InitComplating()
        {
            if (Config.WebConfig.RpcSystemType != "sys.sync")
            {
                return;
            }
            else if (Config.WebConfig.IsEnableError)
            {
                LocalErrorManage.SetAction(new ErrorEvent(this._Service));
                this._RouteService.AddRoute<RefreshError>("RefreshError", _Refresh);
            }
        }

        private void _Refresh(RefreshError data, MsgSource source)
        {
            this._Service.Refresh(data.ErrorId);
        }
    }
}
